




/*
'===============================================================================
'  LinqHelper.DAO.NewsBase
'===============================================================================
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using LinqHelper;
using LinqHelper.Entity;
using LinqHelper.DAO;

namespace LinqHelper.DAO
{
	public class LqNewsBase
	{
		public LqProvider provider = new LqProvider();
		
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public LqNewsBase()
		{
			// Nothing for now.
		}
		
		public void Insert(LqNewsEntity obj)
		{
			provider.GetTable<LqNewsEntity>().InsertOnSubmit(obj);
            provider.SubmitChanges();
		}

		public void Update(LqNewsEntity _obj)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.Id == _obj.Id
                    select obj;
			LqNewsEntity tmp = q.First<LqNewsEntity>();
			
			tmp.NewsId = _obj.NewsId;
			tmp.Title = _obj.Title;
			tmp.Absolute = _obj.Absolute;
			tmp.Contents = _obj.Contents;
			tmp.Photos = _obj.Photos;
			tmp.CreatedDate = _obj.CreatedDate;
			tmp.CreatedBy = _obj.CreatedBy;
			provider.SubmitChanges();
		}
		
		public void Delete(LqNewsEntity obj)
		{
			provider.GetTable<LqNewsEntity>().DeleteOnSubmit(obj);
            provider.SubmitChanges();
		}
		
		
		public void DeleteById(Guid Id)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.Id == Id
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByNewsId(string NewsId)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.NewsId == NewsId
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByTitle(string Title)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.Title == Title
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByAbsolute(string Absolute)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.Absolute == Absolute
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByContents(string Contents)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.Contents == Contents
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByPhotos(string Photos)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.Photos == Photos
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByCreatedDate(DateTime CreatedDate)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.CreatedDate == CreatedDate
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public void DeleteByCreatedBy(string CreatedBy)
		{
			var q = from obj in provider.GetTable<LqNewsEntity>()
                    where obj.CreatedBy == CreatedBy
                    select obj;
					
            LqNewsEntity ob = (LqNewsEntity)q.First<LqNewsEntity>();
            provider.GetTable<LqNewsEntity>().DeleteOnSubmit(ob);
            provider.SubmitChanges();
		}
		
		
		public LqNewsEntity SelectOne(Guid Id)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.Id == Id
                        select obj;
            return query.First<LqNewsEntity>();
		}

		public List<LqNewsEntity> SelectAll()
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectById(Guid Id)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.Id == Id
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByNewsId(string NewsId)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.NewsId == NewsId
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByTitle(string Title)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.Title == Title
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByAbsolute(string Absolute)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.Absolute == Absolute
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByContents(string Contents)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.Contents == Contents
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByPhotos(string Photos)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.Photos == Photos
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByCreatedDate(DateTime CreatedDate)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.CreatedDate == CreatedDate
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		public List<LqNewsEntity> SelectByCreatedBy(string CreatedBy)
		{
			var query = from obj in provider.GetTable<LqNewsEntity>()
                        where obj.CreatedBy == CreatedBy
                        select obj;
            return query.ToList<LqNewsEntity>();
		}
		
		
		

	}
}
